<!--  -->
<template>
    <div class="cssToolbar">
        <a-space>
            <Toolbar :items="['查询', '审核']" @select="cx" @audit="shenghe"></Toolbar>
        </a-space>
    </div>
    <div class="cssTable">
        <a-table 
        size="mini"
        :scrollbar="true" sticky-header stripe :bordered="true" :columns="tableColumns"
            :row-selection="{ showCheckedAll: true, width: 50 }" :style="{
                height: 600 + 'px'
            }" v-model:selected-keys="selectedRowKeys" :loading="table.tableLoading" :data="table.dataList"
            :pagination="false" :rowKey="rowKey">
            <template #planOrderState="{ record }">
                <a-button v-if="record.planOrderState == 2" type="primary" size="mini" status="danger" shape="round">
                    紧急&nbsp
                </a-button>
                <a-button v-if="record.planOrderState == 1" type="primary" size="mini" status="success" shape="round">
                    &nbsp&nbsp急&nbsp&nbsp
                </a-button>
                <a-button v-if="record.planOrderState == 0" status="danger" size="mini" shape="round">
                    正常&nbsp
                </a-button>
            </template>

          <template #planState="{ record }">
                <span v-if="record.planState == 0">自行生产</span>
            </template>
        </a-table>
     <paginationCopys :total="total" show-total show-jumper show-page-size @change="PageSize" @page-size-change="change1" style="justify-content: center"/>    </div>

</template>

<script lang='ts' setup>
import { reactive, toRefs, ref, onMounted } from 'vue'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'
import Toolbar from '@/components/Toolbar.vue'
import { post } from '@/api/http'
import { Message } from '@arco-design/web-vue'
import { Modal } from '@arco-design/web-vue'
const total = ref(10);
const page = ref(1);
const size = ref(10);
function PageSize(val: any) {
  page.value=val
  doRefresh();
}
function change1(val: any) {
  size.value=val
  doRefresh();
}

function doRefresh() {
    post({
        url: "planSingle/planSchedul/getPage",
        data: {
            page: page.value,
            size: size.value,
            schedulState: 1
        },
    })
        .then(({ data, code }: any) => {
            if (code === 200) {
                table.handleSuccess(data.list);
              total.value=data.total;
            }
        })
        .catch(console.log);
}
const cx = () => {
    doRefresh()
}
const pageData: any = ref({
    rHeight: 0
})
onMounted(() => {
    pageData.rHeight = document.getElementsByClassName("main-section")[0]?.clientHeight
})

const { selectedRowKeys } = useRowSelection()
const tableColumns = useTableColumn([
    {
        title: "排产号",
        key: "schedulCode",
        dataIndex: "schedulCode",
        width: 150,
    },
    {
        title: "计划单号",
        key: "planOrderCode",
        dataIndex: "planOrderCode",
        width: 150,
    },
    {
        title: "计划类型",
        key: "planType",
        dataIndex: "planType",
        width: 150,
    },
    {
        title: "客户",
        key: "customName",
        dataIndex: "customName",
        width: 150,
    },
    {
        title: "机台号",
        key: "schedulMachineCode",
        dataIndex: "schedulMachineCode",
        width: 150,
    },
    {
        title: "坯布编号",
        key: "greyCode",
        dataIndex: "greyCode",
        width: 200,
    },
    {
        title: "坯布名称",
        key: "greyName",
        dataIndex: "greyName",
        width: 450,
    },
    {
        title: "产品类别",
        key: "productType",
        dataIndex: "productType",
        width: 150,
    },
    {
        title: "面料种类",
        key: "fabricType",
        dataIndex: "fabricType",
        width: 150,
    },
    {
        title: "品牌",
        key: "brandName",
        dataIndex: "brandName",
        width: 150,
        align: 'left'
    },
    {
        title: "下单重量",
        key: "orderWeight",
        dataIndex: "orderWeight",
        width: 150,
    },
    {
        title: "加工单价",
        key: "machinPrice",
        dataIndex: "machinPrice",
        width: 150,
    },
    {
        title: "加工金额",
        key: "machinMoney",
        dataIndex: "machinMoney",
        width: 150,
    },
    {
        title: "计划单状态",
        key: "planOrderState",
        dataIndex: "planOrderState",
        slotName: 'planOrderState',
        width: 150,
        fixed: 'right'
    },
    {
        title: "订单交期",
        key: "orderDeliveryDate",
        dataIndex: "orderDeliveryDate",
        width: 150,
    },
    {
        title: "计划状态",
        key: "planState",
        dataIndex: "planState",
        slotName: 'planState',
        width: 150,
    },
])
const table = useTable()
const editHandler = (record: any) => {

}

const shenghe = () => {
    if (selectedRowKeys.value.length === 0) {
        Message.error('请先勾选')
        return
    }
    if (selectedRowKeys.value.length > 1) {
        Message.error('只能勾选一条')
        return
    }
    const isArray = table.dataList.filter((val:any)=>{
       return val.id == Number(selectedRowKeys.value)
    })
    console.log(isArray)
    Modal.confirm({
        title: '系统提示',
        content: '订单审核通过已到已排产界面',
        onOk() {
            post({
                url: "planSingle/planSchedul/update",
                data: [{
                    id: Number(selectedRowKeys.value),
                    planOrderCode:isArray[0].planOrderCode,
                    schedulState: Number(2)
                }],
            }).then((res: any) => {
                if (res.code === 200) {
                    post({
                        url:'planSingle/planSchedul/create',
                        data:isArray
                    }).then((res:any)=>{
                        if(res.code != 200){
                            Message.error(res.message)
                        }
                    })
                    doRefresh()
                    selectedRowKeys.value = []
                    Message.success('审核成功')
                } else {
                    Message.error(res.message)
                }
            })
        }
    })
}

const pagination = usePagination(doRefresh)
const rowKey = useRowKey("id")

</script>
<style lang='less' scoped>
.cssToolbar {
    text-align: right;
    margin-bottom: 2px;
}
:deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>